package com.loeng.module.infra.dal.mysql.logger;

import com.loeng.framework.common.pojo.PageResult;
import com.loeng.framework.mybatis.core.mapper.BaseMapperX;
import com.loeng.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.loeng.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
import com.loeng.module.infra.dal.dataobject.logger.ApiErrorLogDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * API 错误日志 Mapper
 *
 * @author loeng zhuo
 */
@Mapper
public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLogDO> {

    default PageResult<ApiErrorLogDO> selectPage(ApiErrorLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ApiErrorLogDO>()
                .eqIfPresent(ApiErrorLogDO::getTraceId, reqVO.getTraceId())
                .eqIfPresent(ApiErrorLogDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ApiErrorLogDO::getUserType, reqVO.getUserType())
                .likeIfPresent(ApiErrorLogDO::getApplicationName, reqVO.getApplicationName())
                .eqIfPresent(ApiErrorLogDO::getRequestMethod, reqVO.getRequestMethod())
                .eqIfPresent(ApiErrorLogDO::getRequestUrl, reqVO.getRequestUrl())
                .eqIfPresent(ApiErrorLogDO::getRequestParams, reqVO.getRequestParams())
                .eqIfPresent(ApiErrorLogDO::getUserIp, reqVO.getUserIp())
                .eqIfPresent(ApiErrorLogDO::getUserAgent, reqVO.getUserAgent())
                .betweenIfPresent(ApiErrorLogDO::getExceptionTime, reqVO.getExceptionTime())
                .likeIfPresent(ApiErrorLogDO::getExceptionName, reqVO.getExceptionName())
                .eqIfPresent(ApiErrorLogDO::getExceptionMessage, reqVO.getExceptionMessage())
                .eqIfPresent(ApiErrorLogDO::getExceptionRootCauseMessage, reqVO.getExceptionRootCauseMessage())
                .eqIfPresent(ApiErrorLogDO::getExceptionStackTrace, reqVO.getExceptionStackTrace())
                .likeIfPresent(ApiErrorLogDO::getExceptionClassName, reqVO.getExceptionClassName())
                .likeIfPresent(ApiErrorLogDO::getExceptionFileName, reqVO.getExceptionFileName())
                .likeIfPresent(ApiErrorLogDO::getExceptionMethodName, reqVO.getExceptionMethodName())
                .eqIfPresent(ApiErrorLogDO::getExceptionLineNumber, reqVO.getExceptionLineNumber())
                .eqIfPresent(ApiErrorLogDO::getProcessStatus, reqVO.getProcessStatus())
                .betweenIfPresent(ApiErrorLogDO::getProcessTime, reqVO.getProcessTime())
                .eqIfPresent(ApiErrorLogDO::getProcessUserId, reqVO.getProcessUserId())
                .betweenIfPresent(ApiErrorLogDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ApiErrorLogDO::getId));
    }

}
